import store from '../../../store/store.js';
import * as ActionTypes from '../../../constants/constants.js';
import {
  isUser, isWxUser, path, saveData, loadData, removeData,
} from '../../../util/utils.js';
import request from '../../../api/request.js';

export async function getStoreClass(options) {
  const { dispatch } = this.props;
  const res = await request.getStoreClass(options);
  if (res.state == 1) {
    dispatch({
      type: ActionTypes.GET_SHOP_CLASS,
      data: res.data,
    });
  }
}

export async function getHotStore(options) {
  const { dispatch } = this.props;
  const res = await request.getHotStore(options);
  if (res.state == 1) {
    dispatch({
      type: ActionTypes.GET_HOT_STORE,
      data: res,
    });
  }
}

export async function getAdsList(options) {
  const { dispatch } = this.props;
  const res = await request.getAdsList(options);
  console.log(res)
  if (res.status == 1) {
    dispatch({
      type: ActionTypes.GET_ADS_LIST,
      data: res.result,
    });
  }
}

export async function getUserTkQyk(options) {
  const { dispatch } = this.props;
  const res = await request.getUserTkQyk(options);
  return new Promise((resolve, reject) => {
    if (res.state == 1) {
      dispatch({
        type: ActionTypes.GET_USER_TK_QYK,
        data: res.data,
      });
      resolve(res);
    } else {
      reject(res);
    }
  });
}

export async function getStoreList_jiaofei(options) {
  const { dispatch } = this.props;
  const res = await request.getStoreList_jiaofei(options);
  if (res.state == 1) {
    dispatch({
      type: ActionTypes.GET_STORE_LIST_JIAOFEI,
      data: res.data,
    });
  }
}
